package com.example.takeaway.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 邢晨旭
 * {@code @date} 2023/10/10
 */
@Getter
@AllArgsConstructor
public enum OssSceneEnum {
    /**
     * 上传场景
     */
    DEFAULT(0, "默认场景", "/default/"),
    AVATAR(1, "头像场景", "/user/avatar/"),
    DISH_LOGO(2, "菜品图片", "/dish/logo/"),
    ;

    private final Integer scene;
    private final String desc;
    private final String path;

    private static final Map<Integer, OssSceneEnum> CACHE;

    static {
        CACHE = new HashMap<>();
        for (OssSceneEnum value : OssSceneEnum.values()) {
            CACHE.put(value.getScene(), value);
        }
    }


    public static OssSceneEnum getByScene(Integer scene) {
        OssSceneEnum ossSceneEnum = CACHE.get(scene);
        if (ossSceneEnum != null) {
            return ossSceneEnum;
        } else {
            throw new RuntimeException("非法的上传场景");
        }
    }
}
